//
//  MPTabBarController.m
//  MobileProject
//
//  Created by caiqilin on 2017/06/30.
//  Copyright © 2017年 caiqilin. All rights reserved.
//

#import "MPTabBarController.h"
#import "MPNavigationController.h"
#import "MPHomeViewController.h"
#import "MPCardViewController.h"
#import "MPAdmiralViewController.h"
#import "MPMoreViewController.h"

@interface MPTabBarController ()

@end

@implementation MPTabBarController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self setupItemTitleTextAttributes];
    
    [self setupChildViewControllers];

}

- (void)setupItemTitleTextAttributes {
    UITabBarItem *item = [UITabBarItem appearance];
    NSMutableDictionary *normalAttrs = [NSMutableDictionary dictionary];
    normalAttrs[NSFontAttributeName] = [UIFont systemFontOfSize:14];
    normalAttrs[NSForegroundColorAttributeName] = [UIColor grayColor];
    [item setTitleTextAttributes:normalAttrs forState:UIControlStateNormal];
    
    NSMutableDictionary *selectedAttrs = [NSMutableDictionary dictionary];
    selectedAttrs[NSForegroundColorAttributeName] = [UIColor darkGrayColor];
    [item setTitleTextAttributes:normalAttrs forState:UIControlStateSelected];
}

- (void)setupChildViewControllers {
    [self setupOneChildViewController:[[MPNavigationController alloc] initWithRootViewController:[[MPHomeViewController alloc] init]] title:@"首页" image:@"tabBar_essence_icon" selectedImage:@"tabBar_essence_click_icon"];
    
    [self setupOneChildViewController:[[MPNavigationController alloc] initWithRootViewController:[[MPCardViewController alloc] init]] title:@"卡牌" image:@"tabBar_new_icon" selectedImage:@"tabBar_new_click_icon"];
    
    [self setupOneChildViewController:[[MPNavigationController alloc] initWithRootViewController:[[MPAdmiralViewController alloc] init]] title:@"武将" image:@"tabBar_friendTrends_icon" selectedImage:@"tabBar_friendTrends_click_icon"];
    
    [self setupOneChildViewController:[[MPNavigationController alloc] initWithRootViewController:[[MPMoreViewController alloc] init]] title:@"更多" image:@"tabBar_me_icon" selectedImage:@"tabBar_me_click_icon"];
}

- (void)setupOneChildViewController:(UIViewController *)vc title:(NSString *)title image:(NSString *)image selectedImage:(NSString *)selectedImage {
    vc.tabBarItem.title = title;
    if (image.length) {
        vc.tabBarItem.image = [UIImage imageNamed:image];
        vc.tabBarItem.selectedImage = [UIImage imageNamed:selectedImage];
    }
    [self addChildViewController:vc];
}

@end
